﻿using MslDiary.Framework;
using MslDiary.Utils;
// 版权所有：2015  All Rights Reserved.
// 文 件 名：RemoveLockViewModel.cs
// 功能描述：
// 创建标识：m.sh.lin0328@163.com 2015/1/7 21:10:36
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Windows.Input;
using MFW = MslDiary.Framework;

namespace MslDiary.ViewModel
{
    public class RemoveLockViewModel : MslDiary.Framework.ViewModelBase
    {
        private System.Windows.Window win = null;
        public RemoveLockViewModel()
        {
            this.LockDiaryPwd = null;
            this.WindowLoadCommand = new CommandBase((Object window) =>
            {
                if (window == null) return;
                this.win = window as System.Windows.Window;
            });
            this.AcceptEnterCommand = new CommandBase((Object win) =>
            {
                if (String.IsNullOrEmpty(this.LockDiaryPwd)) return;
                if (!this.LockDiaryPwd.Equals(MslDiary.Framework.Gloable.DiaryLockPwd))
                {
                    MslDiary.Utils.Helper.Instance.AlertWarning(MslDiary.Framework.ShowMessage.PWD_MSG02);
                    return;
                }
                MslDiary.Framework.Gloable.IsImmediatelyLock = false;
                MslDiary.Utils.Helper.Instance.AlertSuccess(MslDiary.Framework.ShowMessage.LOCK_MSG02);
                if (this.win != null)
                    this.win.Hide();
            });
            this.AcceptCommand = new CommandBase((Object m) =>
            {
                if (String.IsNullOrEmpty(this.LockDiaryPwd))
                {
                    MslDiary.Utils.Helper.Instance.AlertWarning(MslDiary.Framework.ShowMessage.PWD_MSG01);
                    return;
                }
                if (!this.LockDiaryPwd.Equals(MslDiary.Framework.Gloable.DiaryLockPwd))
                {
                    MslDiary.Utils.Helper.Instance.AlertWarning(MslDiary.Framework.ShowMessage.PWD_MSG02);
                    return;
                }
                MslDiary.Framework.Gloable.IsImmediatelyLock = false;
                MslDiary.Utils.Helper.Instance.AlertSuccess(MslDiary.Framework.ShowMessage.LOCK_MSG02);
                if (this.win != null)
                    this.win.Close();
            });
        }

        #region 属性

        private string _lockDiaryPwd;
        /// <summary></summary>
        public string LockDiaryPwd
        {
            get { return _lockDiaryPwd; }
            set
            {
                //base.SetProperty<string>(ref this._lockDiaryPwd, value);
                if (this._lockDiaryPwd == value)
                    return;
                this._lockDiaryPwd = value;
                this.RaisePropertyChanged("LockDiaryPwd");
            }
        }
        #endregion
        #region 命令
        public ICommand AcceptEnterCommand { get; set; }
        public ICommand WindowLoadCommand { get; set; }
        public ICommand AcceptCommand { get; set; }
        public ICommand CancleCommand { get; set; }
        #endregion
        #region 方法

        #endregion
    }
}
